OpenBuildings GenerativeComponents Help

Variable Operations

You may recall from the earlier section, Variables, that you can perform arithmetic-type operations directly upon the contents of a variables.

For example:

balance += deposit   // Equivalent to "balance
= balance + deposit".
eggs--              
// Equivalent to "eggs = eggs - 1".

Variable operations are expressions, since you can use the resultant value within a larger expression or statement.

For example:

Print('The final balance is', balance += deposit);

But you can use variable operations as statements (and perhaps that's their more common use).

balance += deposit;
eggs--;

In the case of the ++ and -- operators, it doesn't matter whether you put the operator before or after the variable, since the result will be ignored anyway.